package algorithm.tree;

import algorithm.model.TreeNode;

/**
 * https://leetcode.com/problems/symmetric-tree/submissions/
 * Easy
 *
 * 判断一个树是否是对称的
 *
 * Created by yzy on 2021-03-16 20:06
 */
public class IsSymmetricTree {

    public boolean isSymmetric(TreeNode root) {
        if(root==null){
            return true;
        }
        return isSymmetricNode(root.left, root.right);
    }

    public boolean isSymmetricNode(TreeNode leftNode, TreeNode rightNode){
        if(leftNode==null && rightNode==null){
            return true;
        }
        if(leftNode==null || rightNode==null){
            return false;
        }
        return leftNode.val==rightNode.val && isSymmetricNode(leftNode.left,rightNode.right) && isSymmetricNode(leftNode.right, rightNode.left);
    }
}
